package com.yeming.flink.practice.source

import java.util.Properties

import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
import org.apache.kafka.common.serialization.StringSerializer

import scala.util.Random

object KafkaSourceKeyValueProducer {

  def main(args: Array[String]): Unit = {

    //kafka设置属性
    val props = new Properties()

    props.setProperty("bootstrap.servers","f2:9092,f3:9092,f4:9092")
    props.setProperty("key.serializer",classOf[StringSerializer].getName)
    props.setProperty("value.serializer",classOf[StringSerializer].getName)

    val producer = new KafkaProducer[String,String](props)

    var r = new Random()
    //不断生产数据
    while (true) {
      val record = new ProducerRecord[String, String]("flinktest01","key" + r.nextInt(100), "value" + r.nextInt(100))
      producer.send(record)
      Thread.sleep(1000)
    }

  }

}
